<?php

class Search extends MY_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('patient_model' , 'PM');
		$this->all_patient = $this->PM->get_patient_data();		
	}
	
	function patient()
	{
		$q = strtolower($this->input->get('term'));
		if (!$q) return;
		
		$this->load->helper('array_to_json');
		
		if(is_array($this->all_patient)){
			$result = array();
			foreach ($this->all_patient['info'] as $value) {
				if (strpos(strtolower($value['code'].' '.$value['first_name'].' '.$value['last_name']), $q) !== false) {
				
					array_push($result, array("id"=>$value['id'], "value"=>($value['first_name'].' '.$value['last_name']) , "code"=>$value['code']));

				}
				if (count($result) > 15)
					break;
			}
			echo array_to_json($result);
			//print_r($result);
		}
	}	

}

/* End of file search.php */
/* Location: ./system/application/controllers/search.php */
